package com.henanuniversity.test;
import java.util.Base64;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class ImageTo64 {
    public static void main(String[] args) throws IOException {
        // 图片文件路径
        String imagePath = "C://Users//Administrator//Desktop//码//图片//小兔.gif";

        // 读取图片文件到字节数组
        Path path = new File(imagePath).toPath();
        byte[] imageBytes = Files.readAllBytes(path);

        // 对字节数组进行Base64编码
        String base64ImageString = Base64.getEncoder().encodeToString(imageBytes);

        // 输出Base64编码后的字符串
        System.out.println(base64ImageString);
    }
}